/**
 * @brief    
 * 
 * @version  0.1
 * @author   yuanchenxi
 * @date     2025.02.19
 *         _
 *     ___| |__   ___ _ __   __ _  ___  _ __   __ _
 *    / __| '_ \ / _ \ '_ \ / _` |/ _ \| '_ \ / _` |
 *    \__ \ | | |  __/ | | | (_| | (_) | | | | (_| |
 *    |___/_| |_|\___|_| |_|\__, |\___/|_| |_|\__, |
 *                          |___/             |___/
 * @copyright (c) 2025 by 神工仿真, All Rights Reserved.
 */

#pragma once
#include "DataStructure/Input/Element/CPYRAMData.h"
#include "DataStructure/Input/Solver/DOFDirections.h"
#include "DBManager/Database/DatabaseFactory.h"
#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"
// #include "DBManager/IService/Input/Property/IPSOLIDService.h"

using SG::DataStructure::FEM::DOFDirections;
using namespace SG::DBManager;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;

/// 8节点6面体实体单元
class OnePyram5Ele
{
public:
    OnePyram5Ele()
    {
        DB_SERVICEFACTORY -> ClearDatabase();
        Input (DB_SERVICEFACTORY);
    }

    /// @brief 写入模型数据
    void        Input (const DBServiceFactorySP dbServiceFactory);
    DBServiceFactorySP GetModel () {return DB_SERVICEFACTORY;}
};

void OnePyram5Ele::Input (const DBServiceFactorySP dbServiceFactory)
{
    // 节点写入
    const auto& nodeRepository = dbServiceFactory ->get<INodeService>();
    SG::DataStructure::FEM::NodeData node;
    node.m_id = 1;
    node.m_x[0] = 1.0;
    node.m_x[1] = 1.0;
    node.m_x[2] = 2.0;
    nodeRepository ->Add  (node);
    node.m_id = 2;
    node.m_x[0] = 10.0;
    node.m_x[1] = 0.0;
    node.m_x[2] = 4.0;
    nodeRepository ->Add  (node);
    node.m_id = 3;
    node.m_x[0] = 0.0;
    node.m_x[1] = 10.0;
    node.m_x[2] = 0.0;
    nodeRepository ->Add  (node);
    node.m_id = 5;
    node.m_x[0] = 10.0;
    node.m_x[1] = 10.0;
    node.m_x[2] = 2.0;
    nodeRepository ->Add  (node);
    node.m_id = 12;
    node.m_x[0] = 0.0;
    node.m_x[1] = 10.0;
    node.m_x[2] = 10.0;
    nodeRepository ->Add  (node);

    // 截面属性写入
    {

    }
    // 写入单元i
    {
        SG::DataStructure::FEM::CPYRAM5Data ElementData;
        ElementData.m_id = 1;
        ElementData.m_g[0] = 1;
        ElementData.m_g[1] = 2;
        ElementData.m_g[2] = 5;
        ElementData.m_g[3] = 3;
        ElementData.m_g[4] = 12;
        dbServiceFactory -> get<IElementService>()->Add (ElementData);
    }
    // 节点固定约束

    // 工况
    {
        // subcase.
        SG::DataStructure::FEM::Subcase subcase;
        // subcase.m_id   = 1;
        // subcase.m_spc  = 1;
        // subcase.m_load = 1;
        // dbServiceFactory->get<ISubcaseService> ()->Add (subcase);
        subcase.AddParameter({"SUBCASE","1"});
        subcase.AddParameter({"SOL","101"});
        subcase.AddParameter({"SPC","1"});
        subcase.AddParameter({"LOAD","1"});
        dbServiceFactory->get<ISubcaseService> ()->Initial (subcase.Dump());
    }
}